package plantshop.view.listeners;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.Serializable;

import plantshop.view.PlayerMenu;


public class NameListener implements KeyListener, Serializable {
	private static final long serialVersionUID = 6346234002984159528L;
	PlayerMenu menu;
	
	NameListener(PlayerMenu menu){
		this.menu = menu;
	}
	
	@Override
	public void keyTyped(KeyEvent e) {
		if(e.getKeyChar() != KeyEvent.VK_BACK_SPACE){
			menu.addLetterToName(e.getKeyChar());
		}
		menu.repaint();
	}

	@Override
	public void keyPressed(KeyEvent e) {
		switch(e.getKeyCode()){
		case KeyEvent.VK_ENTER:
			if(menu.getPlayerName() != "")
				menu.setNeedsName(false);
			break;
		case KeyEvent.VK_BACK_SPACE:
			menu.removeLetter();
			break;
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
	}

}
